<script>
var url;
	$(document).ready(function(){
		// load grid
		$(function(){
			$('#dg').datagrid({url:"<?=base_url()?>transkrip_sementara/grid"});	
			//$('#dg').datagrid('enableFilter'); 			
		});
		
		// load mahasiswa
		load_mahasiswa = function(){
			$('#nim').combogrid({
				panelWidth:450,
				panelHeight:275,
				value:'<?=$this->session->userdata('username'); ?>',
			 
				idField:'nim',
				textField:'nama',
				url:base_url+'prosedur/getMahasiswa2/'+$('#kd_prodi').val(),
				columns:[[
					{field:'nim',title:'NIM',width:130},
					{field:'nama',title:'Nama',width:250}
				]]
			});
		}
		
		// onchange
		$('#kd_fakultas').change(function(){
			$('#kd_prodi').load(base_url+'prosedur/getProdibyFakultas/'+$('#kd_fakultas').val());
			//load_matakuliah();
		});
		$('#kd_prodi').change(function(){
			$('#nim').load(base_url+'prosedur/getMahasiswa2/'+$('#kd_prodi').val());
		});
		$('#kd_prodi').change(function(){
			$('#kd_kurikulum').load(base_url+'prosedur/getKurikulumbyProdi/'+$('#kd_prodi').val());
		});
		$('#nim').change(function(){
			load_matakuliah();
		});
		
		// load matkul
		$(function(){ // init
			$('#dg').datagrid({
				url:"<?=base_url()?>transkrip_sementara/getdata_matkul"
			});
				//$('#dg').datagrid('enableFilter'); 
		});
		
		load_matakuliah = function(){
			$('#dg').datagrid('load',{
				kd_fakultas : $('#kd_fakultas').val(),
				kd_prodi : $('#kd_prodi').val(),
				nim : $('#nim').val()
			});
		}
		
		//# Tombol Bawah
		$(function(){
			var pager = $('#dg').datagrid().datagrid('getPager');	// get the pager of datagrid
			pager.pagination({
				buttons:[
					{
						iconCls:'icon-print',
						text:'Export PDF',
						handler:function(){
							var kd_fakultas = $('#kd_fakultas').val();
							var kd_prodi = $('#kd_prodi').val();
							var kd_kurikulum = $('#kd_kurikulum').val();
							var nim = $('#nim').val();
							if (kd_fakultas != '' && kd_prodi != '' && kd_kurikulum != '' && nim != ''){
								window.open('<?=base_url().'transkrip_sementara/laporan_pdf/'?>'+kd_fakultas+'/'+kd_prodi+'/'+kd_kurikulum+'/'+nim);
							}else{
								$.messager.show({
									title: 'Warning',
									msg: 'Harap Isi Filter Terlabih Dahulu'
								});
							}
						}
					}
				]
			});			
		});
		
		$('#nim').ready(function() {
		  load_matakuliah();
		});
	});
</script>
<table id="dg" title="Transkrip Nilai Sementara" data-options="
			rownumbers:true,
			singleSelect:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:30,
			fit:true,
			toolbar:'#toolbar-matakuliah',
			view:groupview,
			groupField:'semester',
			groupFormatter:function(value, rows){
				return 'Semester ' + value;
			}
			">
<thead>
		<tr>
			<!--<th field="tahun_penerimaan" sortable="true" width="80">Tahun Penerimaan</th> -->
			<!--<th data-options="field:'ck',checkbox:true"></th>-->
			<th field="kd_matakuliah" width="100">Kode Matkul</th>
			<th field="nama_matakuliah" width="300">Nama Matkul</th>
			<th field="sks" width="75">SKS</th>
			<th field="nilai_huruf" width="75">Nilai</th>
		</tr>
</thead>
</table>
<div id="toolbar-matakuliah" style="padding:5px;height:auto">
	<div class="fsearch">
		<table width="700" border="0">
		  <tr>
			<td>Fakultas</td>
			<td>: 
				<select id="kd_fakultas" name="kd_fakultas" style="width:220px;">
					<?=$this->mdl_prosedur->OptionFakultas();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td>Mahasiswa</td>
			<td>: 
				<select id="nim" name="nim" style="width:220px;">
					<?=$this->mdl_prosedur->OptionComboMahasiswa2(array('value' => $this->session->userdata('username')));?>
				</select>
			</td>
		  </tr>
		  <tr>
			<td>Program Studi</td>
			<td>: 
				<select id="kd_prodi" name="kd_prodi" style="width:220px;">
					<?=$this->mdl_prosedur->OptionProdi();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<!--<td>&nbsp;</td>
			<td> 
				<a href="#" onclick="exportPDF()" class="easyui-linkbutton" iconCls="icon-print">Export PDF</a>
			</td>-->
		</tr>
		</table>
	</div>
</div>